package com.njwb.day15.dao.impl;

import com.njwb.day15.dao.AccountDao;
import com.njwb.day15.pojo.Account;
import com.njwb.day15.util.JdbcTemplate;

import java.sql.SQLException;
import java.util.List;

public class AccountDaoImpl implements AccountDao {
    @Override
    public int updateAccount(Account vo) throws SQLException {
        return JdbcTemplate.executeUpdate("update tb_account set blance=? where aid = ?" ,vo.getBlance(),vo.getAid());
    }

    @Override
    public List<Account> queryAll() throws SQLException {
        return JdbcTemplate.executeQueryAll("select * from tb_account",r->new Account(r.getString(1),r.getInt(2)));
    }

    @Override
    public Account findAccountById(String aid) throws SQLException {
        return JdbcTemplate.executeQueryOne("select * from tb_account where aid = ?" ,r->new Account(r.getString(1),r.getInt(2)),aid);
    }
}
